//
//  RootVCOfPicText.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/22.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "RootVCOfPicText.h"
#import "ImageTextModle.h"
#import "CellOfPicText.h"
#import "NetWorkingHandle.h"
#import "ImageTextResponse.h"
#import "FlowLayoutWithPicText.h"
#import "PrefixHeader.pch"
#import "VCOfUser.h"
#import "VCOfTools.h"
#import "Settings.h"
@interface RootVCOfPicText ()
@property(nonatomic, retain)NSMutableArray *mArrOfData;

@property(nonatomic, retain)NSString *strOfhand_id;
@end

@implementation RootVCOfPicText


- (void)dealloc
{
    [_mArrOfData release];
    [_strOfhand_id release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.collectionView.backgroundColor = [UIColor greenColor];
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Register cell classes
    self.collectionView.backgroundColor = [UIColor clearColor];
    
    
    [self GetData];
    [self.collectionView registerClass:[CellOfPicText class] forCellWithReuseIdentifier:@"pool1"];
    
    // Do any additional setup after loading the view.
}

- (void)GetData{
    
    
    
    self.mArrOfData = [NSMutableArray array];
    NSString *url = @"http://m.shougongke.com/index.php?&c=Course&a=newCourseList&gcate=allcate&order=new&vid=18";
    NetWorkingHandle *net = [[NetWorkingHandle alloc]init];
    
    [net netWorkingHandlerGetWithURL:url completion:^(id result, NSData *data, NSURLResponse *response, NSError *error) {
        
        NSArray *arr = [result objectForKey:@"data"];
        
        for (NSDictionary *dic in arr)
        {
            ImageTextModle *model = [[ImageTextModle alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.mArrOfData addObject:model];
            
            [model release];
        }
        
        [self.collectionView reloadData];
        
    }];
}





- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    

    return self.mArrOfData.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CellOfPicText *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool1" forIndexPath:indexPath];
    
    cell.model = self.mArrOfData[indexPath.row];
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ImageTextModle *model = [self.mArrOfData objectAtIndex:indexPath.row];
    FlowLayoutWithPicText *layout = [[FlowLayoutWithPicText alloc]init];
    ImageTextResponse *vc = [[ImageTextResponse alloc]initWithCollectionViewLayout:layout Model:model];
    vc.strOfhandId = model.hand_id;
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, CGRectGetHeight(vc.view.bounds));
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    vc.collectionView.pagingEnabled = YES;
    
    
    
//    ModelOfPic *model = [self.mArrOfData objectAtIndex:indexPath.row];
//    self.strOfhand_id = model.hand_id;
    NSLog(@"%@", self.strOfhand_id);
//    [self.navigationController pushViewController:vc animated:YES];
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    [layout release];
    [vc release];
    
    
}


@end
